﻿using System;

namespace Demo
{

    /*****
     * M公司为某电影院开发了一套影院售票系统，在该系统中需要为不同类型的用户提供不同的电影票打折方式，具体打折方案如下：
    （1）学生凭学生证可享受票价8折优惠；
    （2）年龄在10周岁以及以下的儿童可以享受每张票减免10元的优惠（原始票价需要大于20元）；
    （3）影院VIP用户除享受票价八折优惠外还可以进行积分，积分累计到一定额度可以换取电影院赠送的奖品；
    该系统在将来还可能会根据需求引入更多的打折方案。　*****/


    class Program
    {
        static void Main(string[] args)
        {
            MovieTicket mt = new MovieTicket();
            double originalPrice = 60.0;
            double currentPrice = originalPrice;

            mt.Price = originalPrice;
            Console.WriteLine("原始票价：{0}", originalPrice);
            Console.WriteLine("----------------------------------------");

            //在这里传入相应的 策略类，
            IDiscount discount = AppConfigHelper.GetStrategyInstance() as IDiscount; //new ChildrenDiscount() as IDiscount ;  
            if (discount != null)
            {
                mt.Discount = discount;
                currentPrice = mt.Price;
            }
            Console.WriteLine("折后票价：{0}", currentPrice);

            Console.ReadKey();
        }
    }

    public class MovieTicket
    {
        private double _price;
        private IDiscount _discount;

        public double Price
        {
            get
            {
                return _discount.Calculate(_price);
            }
            set
            {
                _price = value;
            }
        }

        public IDiscount Discount
        {
            set
            {
                _discount = value;
            }
        }

    }

    /// <summary>
    /// 抽象策略类：折扣Discount
    /// </summary>
    public interface IDiscount
    {
        double Calculate(double price);
    }

    /// <summary>
    /// 具体策略类：学生票折扣StudentDiscount
    /// </summary>
    public class StudentDiscount : IDiscount
    {
        public double Calculate(double price)
        {
            Console.WriteLine("学生票：");
            return price * 0.8;
        }
    }

    /// <summary>
    /// 具体策略类：VIP会员票VIPDiscount
    /// </summary>
    public class VIPDiscount : IDiscount
    {
        public double Calculate(double price)
        {
            Console.WriteLine("VIP票：");
            Console.WriteLine("增加积分！");
            return price * 0.5;
        }
    }

    /// <summary>
    /// 具体策略类：儿童票折扣ChildrenDiscount
    /// </summary>
    public class ChildrenDiscount : IDiscount
    {
        public double Calculate(double price)
        {
            Console.WriteLine("儿童票：");
            return price - 10;
        }
    }







































}
